package com.vision.sales.cl.data;

import com.sencha.gxt.core.client.ValueProvider;
import com.vision.sales.cm.data.IHasSalesInvoice;
import com.vision.sales.cm.db.data.SalesInvoice;

/**
 * Custom null-safe {@link ValueProvider} implementation for retrieving a
 * {@link SalesInvoice}'s invoiceNo property value.
 * 
 * @author Mark
 *
 */
public class SalesInvoiceNoValueProvider<T extends IHasSalesInvoice> implements ValueProvider<T, String> {

	@Override
	public String getValue(T object) {
		SalesInvoice invoice = object.getSalesInvoice();
		return invoice == null ? null : invoice.getGroupAndNo();
	}

	@Override
	public void setValue(T object, String value) {
		if (object.getSalesInvoice() == null) {
			object.setSalesInvoice(new SalesInvoice());
		}
		object.getSalesInvoice().setGroupAndNo(value);
	}

	@Override
	public String getPath() {
		return "salesInvoice.groupAndNo";
	}

}
